package com.nulldev.util.web.flexibleKit.scfk;

import com.nulldev.util.web.HttpClient.HttpMethod;

public enum HTTPRequestType {
	GET("GET"),
	POST("POST"),
	OPTIONS("OPTIONS"),
	PUT("PUT"),
	DELETE("DELETE"),
	HEAD("HEAD"),
	TRACE("TRACE"),
	PATCH("PATCH"),
	CONNECT("CONNECT");

	public final String raw;

	private HTTPRequestType(final String raw) {
		this.raw = raw;
	}

	public static HTTPRequestType fetch(final String REQUEST_TYPE) {
		for (final HTTPRequestType type : values()) {
			if (type.raw.equals(REQUEST_TYPE)) {
				return type;
			}
		}
		return GET;
	}

	public static HTTPRequestType from(final HttpMethod method) {
		switch (method) {
			case CONNECT:
				return CONNECT;
			case DELETE:
				return DELETE;
			case GET:
				return GET;
			case HEAD:
				return HEAD;
			case OPTIONS:
				return OPTIONS;
			case PATCH:
				return PATCH;
			case POST:
				return POST;
			case PUT:
				return PUT;
			case TRACE:
				return TRACE;
			default:
				throw new UnsupportedOperationException("Unknown method: " + method);
		}
	}
}
